package com.wwt.server.config;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
/**
 * 全局日期格式转换
 * 前端传的是String 类型 接口上接受的是LocalDate类型
 */
public class DateConvertConfig implements Converter<String, LocalDate> {
    @Override
    public LocalDate convert(String s) {
        try {
            return LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
}
